package com.hpin.fansea.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.hpin.fansea.R;
import com.hpin.fansea.bean.ExpressListBeanData;
import com.hpin.fansea.utils.CommonUtils;
import com.hpin.fansea.utils.Constant;

import java.util.List;

/**
 * Created by Aaron on 15/9/15.
 */
public class ExpressAdapter extends BaseAdapter {

    private Context context;
    private List<ExpressListBeanData> data;

    public ExpressAdapter(Context context, List<ExpressListBeanData> data) {
        this.context = context;
        this.data = data;
    }

    public void setData(List<ExpressListBeanData> data) {
        this.data = data;
    }

    @Override
    public int getCount() {

//        LogUtil.e("tag", "===== count" + data.size());
        return data.size();

    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.item_express, null);
            viewHolder = new ViewHolder();
            viewHolder.tv_goods = (TextView) convertView.findViewById(R.id.tv_goods);
            viewHolder.tv_count = (TextView) convertView.findViewById(R.id.tv_count);
            viewHolder.tv_time = (TextView) convertView.findViewById(R.id.tv_time);
            viewHolder.tv_receiver = (TextView) convertView.findViewById(R.id.tv_receiver);
            viewHolder.tv_status = (TextView) convertView.findViewById(R.id.tv_status);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        //代收商品: 包裹
        viewHolder.tv_goods.setText("代收商品: " + data.get(position).collectingGoods);
        //件数
        viewHolder.tv_count.setText(CommonUtils.isNull(data.get(position).numbers)? "" : data.get(position).numbers+ "件");
        //时间 (受理时间)
        viewHolder.tv_time.setText(data.get(position).acceptTime);
        //收件人
        viewHolder.tv_receiver.setText("收件人: " + data.get(position).addressee);
        //当前状态
        if (Constant.EXPRESS_RECEOVERED.equals(data.get(position).status))
            viewHolder.tv_status.setText("当前状态: 已签收");
        else
            viewHolder.tv_status.setText("当前状态: 未签收");

        return convertView;
    }

    private class ViewHolder {
        public TextView tv_goods;
        public TextView tv_count;
        public TextView tv_time;
        public TextView tv_receiver;
        public TextView tv_status;
    }

}
